﻿using System;
using System.Threading;
using RPGOnline.Remoting;
using RPGOnline.Remoting.Entities;
using RPGOnlineWPF.Model.Interfaces;
using RPGOnlineWPF.Utilities;
using RPGOnlineWPF.ViewModel;

namespace RPGOnlineWPF.Model
{
	public class ChatDataService : IChatService
	{
		private ChatManager m_chatManager;
		private UserManager m_userManager;
		private SessionContext m_sessionContext;
		private GroupManager m_groupsManager;
		private DiceRoller m_diceRoller;

		public ChatDataService()
		{
			m_chatManager = new ChatManager("localhost", 12345);
			m_userManager = new UserManager("Balrog994_WPF", new System.Drawing.Font("Microsoft Sans Serif", 8), System.Drawing.Color.Magenta);
			m_sessionContext = new SessionContext();
			m_groupsManager = new GroupManager(m_sessionContext, m_userManager, m_chatManager);
			m_diceRoller = new DiceRoller(m_userManager);
		}

		public ChatManager GetChatManager()
		{
			return m_chatManager;
		}

		public GroupManager GetGroupManager()
		{
			return m_groupsManager;
		}

		public SessionContext GetSessionContext()
		{
			return m_sessionContext;
		}

		public UserManager GetUserManager()
		{
			return m_userManager;
		}

		public void SendMessage(Guid groupId, string messageToSend)
		{
			m_chatManager.Notify.SendMessage(groupId, m_userManager.CurrentUser, messageToSend);
		}

		public bool IsCurrentUser(User user)
		{
			return m_userManager.CurrentUser.Equals(user);
		}

		public void Roll(int howMany, int dice, int modifier)
		{
			var rollResult = m_diceRoller.Roll(howMany, dice, modifier);
			m_chatManager.Notify.Roll(m_userManager.CurrentUser, rollResult);
		}
	}
}